<?php
error_reporting(E_ALL);
require_once("config.php");
require_once("securitylib.php");
require_once("querylib.php");
require_once("templatelib.php");

session_start();
$_SESSION['sitecheck'] = "ok";

mysql_connect($config_mysql_host, $config_mysql_user, $config_mysql_pass);
mysql_select_db($config_mysql_name);
$prefix = $config_mysql_prefix;

if (!mysql_query("SELECT * from dcms_users;"))
{
	?>
		<h1>Welcome to DefinitveCMS!</h1>
		<p>Installing DCMS...</p>
	<?php
	$sqldata = get_file("default.sql");
	$sqldata = str_replace("\n", "", $sqldata);
	$queries = explode(";", $sqldata);
	$ok = true;
	foreach ($queries as $query)
	{
		
		if (!mysql_query($query))
		{
			echo "Query failed:<br />\n$query<br />\n";
			$ok = false;
		}
	}
	
	if ($ok)
	{
		?>
		<p>Installation successful!</p>
		<p>Some extra information to get you started:</p>
		<p>
			Admin account: <strong>admin</strong> with password <strong>admin</strong>. PLEASE CHANGE THE PASSWORD!<br />
			Make the directory 'userfiles' writable with your FTP client our shell.<br />
			<strong>WHEN EVERYTHING WORKS, DELETE install.php!!!</strong>
		</p>
		<?php
	}
	else
	{
		?>
		<p>Installation failed!</p>
		<?php
	}
}

?>